#ifndef CONNECTIONPLAYER_H
#define CONNECTIONPLAYER_H

#include <QString>
#include <QtCore/QList>
#include <QtCore/QPoint>
#include "connection.h"
#include <QtCore/QtCore>
#include "playerinput.h"
#include "playermove.h"

class ConnectionPlayer : public Connection
{
	Q_OBJECT
public:
	ConnectionPlayer(QHostAddress a, quint16 p, bool onlyReceive = false);
	ConnectionPlayer(bool onlyReceive = false);

    void setNick(QString n);
    void setScore(quint16 n);
    void setPlayerId(quint8 n);
    void setPosition(QPointF pos);

    void setVelocity(QPointF vel);
	void setIsAlive(bool isAlive);
	void setIsReloading(bool isReloading);
	void setIsShooting(bool isShooting);
	void setAngle(qreal angle);
	void setHealth(qreal h);
	void setDirs(quint8 d1, quint8 d2);
	void setUsesMouse(bool um);
	void setIsRemote(bool ir);
	void setDeathTime(quint32 dt);
	void setPlayerTime(quint32);

	bool movePlayerBy(qreal dx, qreal dy);
	bool movePlayerBy(QPointF v);

	void decreaseHealth(qreal h);
	void increasePlayerTime();

    QString getNick();
    quint16 getScore();
    quint8 getPlayerId();
    QPointF getPos();
    QPointF getVelocity();
    bool getIsAlive();
    bool getIsReloading();
    bool getIsShooting();
    qreal getAngle();
    qreal getSpeed();
    qreal getHealth();
    bool getUsesMouse();
    bool getIsRemote();
    quint32 getDeathTime();
	quint32 getPlayerTime();
	QVector<PlayerMove> &getPlayerMoveList();

    QList<quint8> dirs;
    quint8 dir[2];
    QPointF getVelocityByDirs(quint8 dir1, quint8 dir2);
    void updatePlayerByDelta(quint32 delta);
    void playerTimeTick();
    void deadPlayerTimeTick();

    void emitGunFired(qreal x, qreal y, qreal angle);
protected:

    QString nick;
    quint8 player_id;
    quint16 score;

    bool isAlive;
    bool isReloading;
    bool isShooting;
    QPointF pos;
    QPointF velocity;

    qreal angle;
	qreal speed;
	qreal health;
	qreal radius;

    bool usesMouse;
    bool isRemote;

    quint32 deathTime;
    quint32 playerTime;

    QVector<PlayerMove> playerMoveList;
    void receiveInput(quint32 time, PlayerInput& playerInput);
signals:
    void newInputAdded();
    void deadTimeTick();
    void positionChanged();
    void gunFired(qreal x, qreal y, qreal angle);
};

#endif // CONNECTIONPLAYER_H
